<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <header class="head" style="padding-top:0.4rem;">
        <div class="head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
        <h3>修改登录密码</h3>
        <div class="head-r"></div>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>
    <ul class="list-input mt20">
        <li>
            <label><i>*</i>原登录密码:</label>
            <input type="password" placeholder="输入6-16位密码" id="oldPassword">
        </li>
        <li>
            <label><i>*</i>新登录密码:</label>
            <input type="password" placeholder="输入6-16位密码" id="password">
        </li>
        <li>
            <label><i>*</i>确认新密码:</label>
            <input type="password" placeholder="输入6-16位密码" id="password2">
        </li>
    </ul>
    <div class="btn-1 mt100 mb30" onclick="save();">提交</div>


</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">

    apiready = function(){

    }

    // 修改密码
    function save(){
        var password_old = $api.byId('oldPassword').value;
        var password = $api.byId('password').value;
        var password2 = $api.byId('password2').value;

        if (!password_old) {
            api.toast({
                msg: '请输入原密码!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if (!password) {
            api.toast({
                msg: '请输入新密码!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if (!password2) {
            api.toast({
                msg: '请再次输入新密码!',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        if (password != password2) {
            api.toast({
                msg: '两次输入密码不一致!',
                duration: 2000,
                location: 'bottom',
            });
            return false;
        }
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/user/password/update-login',
            method: 'post',
            data: {
                values: {
                    password: password,
                    password_old: password_old,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );

                if (ret.status_code == 200) {

                    api.toast({
                        msg: ret.message,
                        duration: 2000,
                        location: 'bottom',
                        global: true,
                    });

                    api.closeWin();
                }
            } else {
                // alert( JSON.stringify( err ) );

                if (err.body.status_code == 401) {
                    api.openWin({
                        name: 'login',
                        url: './login.html',
                        pageParam: {
                            name: 'fix_pwd'
                        }
                    });
                }else{
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                    return false;
                }

            }
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>
